fix: ignore internal cost for ristretto caches#1413
Merged
Conversation
jensneuse
approved these changes
Dec 3, 2024
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Ristretto caches contain an internal cost, which will be added upon each item that is supposed to be written to a cache. As an example with a cache size of
1024and a cost per item of1inSet(), we would anticipate, that we could have up to 1024 items in the cache.If
IgnoreInternalCostis not set totrue, for eachSetoperation, the provided cost will be added to an internal cost which defaults to around56. Therefore we would have a total cost of 57 for adding a single item to the cache.Instead of now being able to store
1024items, we are only able to store17items before keys are starting to get evicted.This PR changes the config to ignore the internal cost per cache
Warning
This change will improve the cache utilization but also have an impact on memory.
Example storing pointers to a struct with the size of
80byte in a cache with1024max cost.In theory we would then have
ptr_size * struct_size * cache_size * size_of_internal_struct8 * 80 * 1024 * 56 = 36700160up to 36 MB of memory for this cache(deviations possible based on OS)
Before:

On the bottom graphs we can see that the
yvalue for the cost on the left is higher than theyvalue of the keys on the right.After:

With the change, the cache cost will now reflect the actual number of keys.
Checklist